package com.example.asus.testskip.DGPhone;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;

import com.example.asus.testskip.R;


/* renamed from: dg.ca.com.DGPhone.CustomTextView */
public class CustomTextView extends android.support.v7.widget.AppCompatTextView implements OnClickListener {
    public static final String TAG = CustomTextView.class.getSimpleName();
    private CallBack callBack;
    private boolean isDrawFinish = false;
    private boolean isDrawHalf = false;
    public boolean isStarting = false;
    private Paint paint = null;
    private float step = 0.0f;
    private String text = "";
    private int textColor;
    private float textLength = 0.0f;
    private float viewWidth = 0.0f;

    /* renamed from: dg.ca.com.DGPhone.CustomTextView$CallBack */
    public interface CallBack {
        void drawFinish();

        void drawHalf();
    }

    /* renamed from: dg.ca.com.DGPhone.CustomTextView$SavedState */
    public static class SavedState extends BaseSavedState {
        public static final Creator<SavedState> CREATOR = new Creator<SavedState>() {
            public SavedState[] newArray(int size) {
                return new SavedState[size];
            }

            public SavedState createFromParcel(Parcel in) {
                return new SavedState(in);
            }
        };
        public boolean isStarting;
        public float step;

        SavedState(Parcelable superState) {
            super(superState);
            this.isStarting = false;
            this.step = 0.0f;
        }

        public void writeToParcel(Parcel out, int flags) {
            super.writeToParcel(out, flags);
            out.writeBooleanArray(new boolean[]{this.isStarting});
            out.writeFloat(this.step);
        }

        private SavedState(Parcel in) {
            super(in);
            this.isStarting = false;
            this.step = 0.0f;
            boolean[] b = null;
            in.readBooleanArray(b);
            if (b != null && b.length > 0) {
                this.isStarting = b[0];
            }
            this.step = in.readFloat();
        }
    }

    public CustomTextView(Context context) {
        super(context);
        initView();
    }

    public CustomTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initView();
    }

    private void initView() {
        setOnClickListener(this);
    }

    public void init(WindowManager windowManager) {
        this.paint = getPaint();
        this.text = getText().toString();
        setTypeface(Typeface.createFromAsset(getContext().getAssets(), "yihei.ttf"));
        this.textLength = this.paint.measureText(this.text);
        this.paint.setFakeBoldText(true);
        this.viewWidth = (float) getWidth();
        if (this.viewWidth == 0.0f && windowManager != null) {
            this.viewWidth = (float) windowManager.getDefaultDisplay().getWidth();
        }
        this.step = 0.0f;
        this.textColor = getResources().getColor(R.color.colorAccent);
    }

    public Parcelable onSaveInstanceState() {
        SavedState ss = new SavedState(super.onSaveInstanceState());
        ss.step = this.step;
        ss.isStarting = this.isStarting;
        return ss;
    }

    public void onRestoreInstanceState(Parcelable state) {
        if (!(state instanceof SavedState)) {
            super.onRestoreInstanceState(state);
            return;
        }
        SavedState ss = (SavedState) state;
        super.onRestoreInstanceState(ss.getSuperState());
        this.step = ss.step;
        this.isStarting = ss.isStarting;
    }

    public void startScroll() {
        this.isStarting = true;
        invalidate();
    }

    public void stopScroll() {
        this.isStarting = false;
        invalidate();
    }

    public void onDraw(Canvas canvas) {
        this.paint.setColor(this.textColor);
        canvas.drawText(this.text, ((float) getRight()) - this.step, ((float) getTop()) + getTextSize() + ((float) getPaddingTop()), this.paint);
        if (this.isStarting) {
            this.step += 2.0f;
            if ((((float) getWidth()) + this.textLength) - 803.0f < this.step && this.step < (((float) getWidth()) + this.textLength) - 800.0f && !this.isDrawHalf) {
                this.callBack.drawHalf();
                this.isDrawHalf = true;
            }
            if (this.step > ((float) getWidth()) + this.textLength && !this.isDrawFinish) {
                this.callBack.drawFinish();
                this.isDrawFinish = true;
            }
            if (this.textLength > ((float) getWidth())) {
                if (this.step > ((float) getWidth()) + this.textLength) {
                    this.step = 0.0f;
                    this.isDrawHalf = false;
                    this.isDrawFinish = false;
                }
            } else if (this.step > ((float) getWidth()) + this.textLength) {
                this.step = 0.0f;
                this.isDrawHalf = false;
                this.isDrawFinish = false;
            }
            invalidate();
        }
    }

    public void onClick(View v) {
        if (this.isStarting) {
            stopScroll();
        } else {
            startScroll();
        }
    }

    public void setCallBack(CallBack callBack2) {
        this.callBack = callBack2;
    }
}
